<!-- 友链编辑弹窗 -->
<template>
  <el-dialog
    :title="isUpdate ? '修改IOS包提审' : '添加IOS包提审'"
    :visible="visible"
    width="750px"
    :destroy-on-close="true"
    :lock-scroll="false"
    :close-on-click-modal="false"
    :before-close="confirmClose"
    @update:visible="updateVisible"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="82px">
      <el-row :gutter="15">
        <el-col :sm="12">
          <el-form-item label="产品名称:" prop="title">
            <el-input
              clearable
              :maxlength="20"
              v-model="form.title"
              placeholder="请输入产品名称"
            />
          </el-form-item>
          <el-form-item label="包名:" prop="bundle_id">
            <el-input
              clearable
              :maxlength="20"
              v-model="form.bundle_id"
              placeholder="请输入包名"
            />
          </el-form-item>
        </el-col>

        <el-col :sm="12">
          <el-form-item label="版本号:" prop="version">
            <el-input
              clearable
              :maxlength="20"
              v-model="form.version"
              placeholder="请输入版本号"
            />
          </el-form-item>
          <el-form-item label="入口状态:" prop="open_flag">
            <el-select
              clearable
              class="ele-block"
              v-model="form.open_flag"
              placeholder="请选择开启状态"
            >
              <el-option label="开启" :value="0" />
              <el-option label="关闭" :value="1" />
            </el-select>
          </el-form-item>
          <el-form-item label="环境:" prop="env">
            <el-select
              clearable
              class="ele-block"
              v-model="form.env"
              placeholder="请选择环境"
            >
              <el-option label="提审环境" :value="0" />
              <el-option label="正式环境" :value="1" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="公告备注:" prop="remark" style="margin-top: 20px">
        <el-input
          :rows="3"
          clearable
          type="textarea"
          :maxlength="200"
          v-model="form.remark"
          placeholder="请输入公告备注"
        />
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="confirmClose()">取消</el-button>
      <el-button type="primary" @click="save" :loading="loading"
        >保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>

export default {
  name: "IosReviewEdit",
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  data() {
    return {
      // 表单数据
      form: Object.assign(
        {
          member_id: "",
          source: "",
          title: "",
          content: "",
          // system_id: ""
        },
        this.data
      ),
      // 表单验证规则
      rules: {
        title: [
          { required: true, message: "请选择产品名称", trigger: "blur" }
        ],
        bundle_id: [
          { required: true, message: "请选择产品名称", trigger: "blur" }
        ],
        version: [
          { required: true, message: "请选择产品名称", trigger: "blur" }
        ],
        open_flag: [
          { required: true, message: "请选择游戏入口状态", trigger: "blur" }
        ],
        content: [
          { required: false, message: "请输入消息内容", trigger: "blur" }
        ]
      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,

      //分页功能
      pageSize: 15, //每页显示条数  6条刚好
      currentPage: 1, //当前页数
      pageCount: 6, //按钮数，超过时会折叠
      pageTotal: 0, //总条数
      itemlist: []
    };
  },


  watch: {
    data() {
      if (this.data) {
        this.form = Object.assign({}, this.data);
        this.isUpdate = true;
      } else {
        this.form = {};
        this.isUpdate = false;
      }
    }
  },
  methods: {
    /* 保存编辑 */
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.loading = true;
          this.$http
            .post("/BoxIosReview/edit", this.form)
            .then(res => {
              this.loading = false;
              if (res.data.code === 0) {
                this.$message.success(res.data.msg);
                if (!this.isUpdate) {
                  this.form = {};
                }
                this.updateVisible(false);
                this.$emit("done");
              } else {
                this.$message.error(res.data.msg);
              }
            })
            .catch(e => {
              this.loading = false;
              this.$message.error(e.message);
            });
        } else {
          return false;
        }
      });
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit("update:visible", value);
    },

    confirmClose() {
      this.$confirm("确定要返回吗？", "温馨提示")
        .then(() => {
          this.updateVisible(false);
          if (!this.isUpdate) {
            this.form = {};
          }
        })
        .catch(() => {});
    }
  }
};
</script>

<style scoped></style>
